<?php
/**
 *  傳入學期,取學期所有班級
 * @author cik
 *
 */
class Sfs_View_Helper_ClassNameOptions
{
    function ClassNameOptions($year_semester,$selected='')
    {

        if ($year_semester=='') {
            $semester_duration = new Semester_Model_SemesterDuration();
            $semester =  $semester_duration->get_curr_year_seme();
            $year_semester = $semester['yearSeme'];

        }

        // 班級
        $semester = new Semester_Model_SemesterClass();
        $arr = explode("-",$year_semester);
        if (isset($arr[2]))
        $className = $semester->getGradeClassNames($arr[0],$arr[1],$arr[2]);
        else
        $className = $semester->getGradeClassNames($arr[0],$arr[1]);

        $str = '';
        foreach ($className as  $id=>$vals){
            $str .='<optgroup label="'.$id.'">'."\n";
            foreach ($vals as $id=>$val) {
                if ($selected == $id)
                $str .='<option value="'.$id.'" selected>'.$val.'</option>'."\n";
                else
                $str .='<option value="'.$id.'">'.$val.'</option>'."\n";
            }
            $str .="</optgroup>\n";
        }
        return $str;
    }
}
